﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;
using University.Workshop.Model;

namespace University.Workshop.WinApp
{
    public partial class Menu : Form
    {
        public Menu()
        {
            InitializeComponent();
        }
        private void callForms(Form form) 
        {
            if (this.MdiChildren.Length > 0)
                this.MdiChildren[0].Close();
            form.MdiParent = this;
            form.Show();
        }

        private void registrarProductoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    RegisterProductForm product = new RegisterProductForm();
                    callForms(product);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void modificarProductoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    ModifyProductForm modifyProduct = new ModifyProductForm();
                    callForms(modifyProduct);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }

        private void modificarAdministradorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    AdministratorView modifyAdministrator = new AdministratorView();
                    callForms(modifyAdministrator);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }

        private void nuevoAdministradorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
               // if (Program.logged)
               // {
                    RegisterAdministrator registerAdmi = new RegisterAdministrator();
                    callForms(registerAdmi);
               // }
               // else
                  //  throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }

        private void ingresarAlSistemaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoginForm login = new LoginForm();
            callForms(login);
        }

        private void Menu_Load(object sender, EventArgs e)
        {
            try
            {
                if (LogOnManager.ExistOperator())
                {
                    LoginForm login = new LoginForm();
                    callForms(login);
                    //bool logg=login.Enabled;
                    //MessageBox.Show(logg.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }            
        }

        private void buscarClienteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    SearchClientSimple client = new SearchClientSimple();
                    callForms(client);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void nuevaHabitacionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    NewRoomForm newRoom = new NewRoomForm();
                    callForms(newRoom);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void reservarHabitacionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {

                    BookingRoomForm bookingroom = new BookingRoomForm();
                    callForms(bookingroom);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void nuevoEmpleadoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    EmployeeForm employee = new EmployeeForm();
                    callForms(employee);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void nuevoClienteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    ClientRegister client = new ClientRegister();
                    callForms(client);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void actualizarDatosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    UpdateClient client = new UpdateClient();
                    callForms(client);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void busquedaDeReservasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    BookingSearchView bookingView = new BookingSearchView();
                    callForms(bookingView);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void checkOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    RoomCheckout checkout = new RoomCheckout();
                    callForms(checkout);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void principalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    PrincipalForm principal = new PrincipalForm();
                    callForms(principal);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void ventasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    StoreProductForm store = new StoreProductForm();                    
                    callForms(store);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void sendEmailToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    TestEmail email = new TestEmail();
                    callForms(email);
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void checkInToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    CheckInForm checkin = new CheckInForm();
                    callForms(checkin);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void imprimirFacturasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    Invoice invoice = new Invoice();
                    callForms(invoice);
                }
                else
                {
                    throw new Exception("You are not logged");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }

        private void reportesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    Reports reporte = new Reports();
                    callForms(reporte);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void búsquedaAvanzadaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    AdvancedSearch search = new AdvancedSearch();
                    callForms(search);
                }
                else
                    throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void loginToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Program.logged)
                {
                    throw new Exception("You are logged");
                }
                else
                {
                    LoginForm login = new LoginForm();
                    callForms(login);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void backupDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
               if (Program.logged)
                {
                BackupDataBaseForm backupForm = new BackupDataBaseForm();
                callForms(backupForm);
                }
                else
                 throw new Exception("You are not logged");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
